package week_5.homework;

import java.io.Serializable;

public class Product implements Serializable,Comparable<Product> {
    private String tradename;//商品名
    private double price;//商品价格
    private int number;//商品编码
    private String brand;//商品品牌

    public Product(String tradename, double price, int number, String brand) {
        this.tradename = tradename;
        this.price = price;
        this.number = number;
        if (brand == null) {
            this.brand = "";
        } else {
            this.brand = brand;
        }
    }

    public Product(String tradename, double price, int number) {
        this(tradename, price,number,"");
    }

    public String getTradename() {
        return tradename;
    }
    public void setTradename(String tradename)
    {
        this.tradename =tradename;
    }
    public double getPrice()
   {
        return price;
   }
   public void setPrice(double price)
   {
       this.price = price;
   }
   public void  setNumber(int number)
   {
       this.number =number;
   }

   public int getNumber()
   {
       return number;
   }
   public String getBrand()
   {
       return brand;
   }
   public void SetBrand(String brand)
   {
        this.brand = brand;
   }

    public String toString()
    {
        String result;
        result = "Tradename:  "+tradename+"  Price:  "+price+ "  number:  "+number+"  brand:  "+brand;
        return result;
    }
    @Override
    public int compareTo(Product otherproduct) {
        if (tradename.compareTo(otherproduct.tradename) > 0) {
            return 1;
        }
        else
        {
            if(tradename.compareTo(otherproduct.tradename) < 0)
                return -1;
            else
            {
                if(price>otherproduct.price)
                    return 1;
                else
                    return -1;
            }
        }
    }
}
